﻿using System.Web.UI.WebControls;
using FredCK.FCKeditorV2;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.ShopSinglePages;
using System.Web;
namespace Ue.Qcdz.UI.Controls
{
    public class ShopSinglePageEdit : SkinnedEntityEdit<ShopSinglePage>
    {
        private TextBox tbxTitle;//标题
        private TextBox tbxImageUrl; 
        private FCKeditor tbxContent;
        private TextBox tbxRemark;
        private TextBox tbxDisplayOrder;
        private RadioButtonList rBtnStatus;
 

        public ShopSinglePageEdit()
        {
            this.ReturnUrl = Domain.SiteUrls.Instance.ShopSinglePages();
        }

        protected override ShopSinglePage Enttiy
        {
            get
            {
                ShopSinglePage model = ShopSinglePageService.GetShopSinglePage(this.EntityKey);

                if (model == null)
                {
                    model = new ShopSinglePage(this.EntityKey);
                    model.Shop = Domain.SiteContext.GetSiteContext().Shop;
                }
                if (tbxTitle != null)
                    model.Title = tbxTitle.GetValue<string>();
                if (tbxImageUrl != null)
                    model.ImageUrl = tbxImageUrl.GetValue<string>();
                if (tbxContent != null)
                    model.Content = tbxContent.Value;
                if (tbxRemark != null)
                    model.Remark = tbxRemark.GetValue<string>();
                if (tbxDisplayOrder != null)
                    model.DisplayOrder = tbxDisplayOrder.GetValue<int>();
                if (rBtnStatus != null)
                    model.Status = rBtnStatus.SelectedValue == "1" ? 1 : 0;

                return model;


            }
            set
            {
                if (value == null)
                    return;
                tbxTitle.SetValue(value.Title);
                tbxImageUrl.SetValue(value.ImageUrl);
                tbxContent.Value = value.Content;
                tbxRemark.SetValue(value.Remark);
                tbxDisplayOrder.SetValue(value.DisplayOrder);
                rBtnStatus.SelectedIndex = -1;
                rBtnStatus.Items.FindByValue(value.Status.ToString()).Selected = true;
                //

            }
        }

        protected override void InitSkin(System.Web.UI.Control skin)
        {
            tbxTitle = skin.FindControl<TextBox>("tbxTitle");
            tbxImageUrl = skin.FindControl<TextBox>("tbxImageUrl");
            tbxContent = skin.FindControl<FCKeditor>("tbxContent");
            tbxRemark = skin.FindControl<TextBox>("tbxRemark");
            tbxDisplayOrder = skin.FindControl<TextBox>("tbxDisplayOrder");
            rBtnStatus = skin.FindControl<RadioButtonList>("rBtnStatus");
        }

        protected override string GetSkinFileName()
        {
            return "~/Themes/zh-cn/Skins/ShopSinglePages/ShopSinglePageEdit.ascx";
        }
    }
}